package com.gedeshidai.shumadevelop.controller;

import com.gedeshidai.shumadevelop.annotation.AuthCheck;
import com.gedeshidai.shumadevelop.common.BaseResponse;
import com.gedeshidai.shumadevelop.common.ResultUtils;
import com.gedeshidai.shumadevelop.constant.UserConstant;
import com.gedeshidai.shumadevelop.model.vo.NumberListReportVO;
import com.gedeshidai.shumadevelop.model.vo.ProductPreviewVO;
import com.gedeshidai.shumadevelop.model.vo.SalesTop20ReportVO;
import com.gedeshidai.shumadevelop.model.vo.TurnoverReportVO;
import com.gedeshidai.shumadevelop.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.xml.transform.Result;
import java.time.LocalDate;

@RestController
@RequestMapping("/admin/report")
@Slf4j
public class ReportController {
    @Resource
    private ReportService reportService;

    /**
     * 总销量统计
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/turnoverStatistics")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<TurnoverReportVO> turnoverStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
            log.info("总销量统计:",begin,end);
        return ResultUtils.success(reportService.getTurnoverStatistics(begin, end));
    }

    /**
     * Top20
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/top20")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<SalesTop20ReportVO> top20(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        log.info("销量排名top20:",begin,end);
        return ResultUtils.success(reportService.getSalesTop20(begin, end));
    }

    /**
     * 兑换方式的数量
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/redemptionType")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<NumberListReportVO> redemptionType(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        log.info("兑换方式的数量:",begin,end);
        return ResultUtils.success(reportService.getNumberList(begin, end));
    }
}
